﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using System.Data.SqlClient;

namespace BLL
{
    public static class TaoMaSo
    {
        /// <summary>
        /// Tạo mã số toa thuốc tăng dần
        /// </summary>
        /// <returns></returns>
        public static int TaoMS(string SQL)
        {
            TruyXuatDB TXDB = new TruyXuatDB();
            int MaSo;
            try
            {
                SqlCommand com = new SqlCommand(SQL, TXDB.Con);
                MaSo = Convert.ToInt16(com.ExecuteScalar());
            }
            catch (Exception)
            {
                MaSo = 0;
            }
            MaSo++;
            return MaSo;
        }

        public static string TaoMS(string SQL, string KQ)
        {
            TruyXuatDB TXDB = new TruyXuatDB();
            string MaSo = "";
            try
            {
                SqlCommand com = new SqlCommand(SQL, TXDB.Con);
                MaSo = com.ExecuteScalar().ToString();
            }
            catch (Exception)
            {
                MaSo = "";
            }
            return MaSo;
        }
    }
}
